Move thread-local connections from examples to recipes#104
Move thread-local connections from examples to recipes#104MeanSquaredError wants to merge 3 commits intorbock:mainfrom
Conversation
…to "thread-local connection" and move it to the PostgreSQL recipes.
…e inserts into tab_bar.
a98fc77 to
0ffcfa0
Compare
rbock
left a comment
There was a problem hiding this comment.
Thanks for the PR!
LGTM except for a couple of nits.
| We define a database connection class called `lazy_connection`, which mimics the regular database connections provided by sqlpp23 and lets the user execute database queries, pretty much like a regular sqlpp connection does. In fact, our lazy connection creates an underlying sqlpp database connection and forwards all database queries to the sqlpp connection, but that sqlpp connection is not | ||
| created immediately in the constructor of the lazy connection. Instead, its creation is postponed until the moment when the user tries to execute their first query through our lazy connection object, which is why our connection class is called "lazy". | ||
|
|
||
| There is only one, global instance of our `lazy_connection` class, called `g_dbc`, which is defined as |
There was a problem hiding this comment.
This sentence seems odd.
In a multi-threaded program, there are multiple instances, because it is not global but thread-local.
There was a problem hiding this comment.
I guess that sentence was not worded very well. Changed it to
Database queries are made through a global object called
g_dbc, which is defined as
Does that make more sense?
There was a problem hiding this comment.
Hmm. Thanks for asking. What's global is the name, but not any object (they are thread-local).
We could say that we create a thread-local variable of typelazy_connection called g_dbc at global scope.
0ffcfa0 to
fa0fc4c
Compare
|
OK, I (hopefully) fixed the issues that you found and also moved some of the text into an initial paragraph, summarizing the purpose of the document. |
As discussed here, this PR moves thread-local connections from examples to recipes and documents the pattern.